'''

功能： 使用字典实现词频计算

涉及方法：
    * 读取文件
    * 按行处理文本
    * dict 计算词频

输入：word.txt
输出：包含每个单词出现词频的 dict

'''

fname = open('word.txt','r')

counts = {}
for line in fname:
    # line = line.rstrip()
    words = line.split(' ')
    for word in words:
        if word not in counts:
            counts[word] = 1
        else:
            counts[word] += 1
print(counts)
fname.close()